<?php
/**
 * Created by PhpStorm.
 * User: aron
 * Date: 2019/5/7
 * Time: 5:29 PM
 */


include_once "../../Util/DebugUtil/DebugUtil.php";

$lamp = array(
    "l" => "Linux",
    "a" => "Apache",
    "m" => "Mysql",
    "p" => "PHP",
);

// array_push 添加元素
DebugUtil::printDebugSeperator();
$opeArr = $lamp;
array_push($opeArr, "Hello", "world");
print_r($opeArr);
// Output:
//Array
//(
//    [l] => Linux
//    [a] => Apache
//    [m] => Mysql
//    [p] => PHP
//    [0] => Hello
//    [1] => world
//)


// array_pop 移除元素
// array_push array_pop 实现的是栈结构
DebugUtil::printDebugSeperator();
$opeArr = $lamp;
$value = array_pop($opeArr);
print($value."\r\n");
print_r($opeArr);
// Output:
//PHP
//Array
//(
//    [l] => Linux
//    [a] => Apache
//    [m] => Mysql
//)


// array_shift 移除元素
// array_push array_shift 实现的是列表结构
DebugUtil::printDebugSeperator();
$opeArr = $lamp;
$value = array_shift($opeArr);
print($value."\r\n");
print_r($opeArr);
// Output:
//Linux
//Array
//(
//    [a] => Apache
//    [m] => Mysql
//    [p] => PHP
//)


// 另一种添加元素到数组的方法，自动会添加下标
$arr = array();
$arr[] = "hello";
$arr[] = "world";
print_r($arr);
// Output:
//Array
//(
//    [0] => hello
//    [1] => world
//)
